import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:fluwx/fluwx.dart' as fluwx;
import 'package:provider/provider.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBEngineer/YBBaseRouter/YBNavigator.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBEngineer/YBProjectPopPage/YBZuZhiGuanLiQuanXianPage.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBEngineer/YBWeChatPopPage/YBWeChatPopPage.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBColor/YBColor.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBImageStyle/YBImageStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBTextStyle/YBTextStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/yb_chinese_text/yb_chinese_text.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBJsonToModel/YBMineModel/YBMineAuthVipModel.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBModule/YBMineModule/YBMineProvider/YBMineUserProvider.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBNetWorkModule/YBAPi/YBAPi.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBUtils/YBBaseUtils/YBCallPhoneUtils.dart';


class YBFengXiangDetailPage extends StatefulWidget {

  final int id;
  final String title;
  final String description;

  const YBFengXiangDetailPage({Key key, this.id, this.title, this.description}) : super(key: key);

  @override
  _YBFengXiangDetailPageState createState() => _YBFengXiangDetailPageState(id: id,title: title,description: description);
}

class _YBFengXiangDetailPageState extends State<YBFengXiangDetailPage> {

  final int id;
  final String title;
  final String description;

  _YBFengXiangDetailPageState({this.id, this.title, this.description});

  @override
  void dispose() {
    // TODO: implement dispose
    EasyLoading.dismiss();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: ChangeNotifierProvider(create:(context)=>YBMineUserProvider()..getUserInfoData(),
        child: Consumer<YBMineUserProvider>(builder: (context,uerInfo,child){
          bool _selectVip = false;
          if (uerInfo.mineUserInfoModel != null){
            for(YBMineAuthVipModel mineAuthModel in uerInfo.mineUserInfoModel.customerAuthorities){
              if (mineAuthModel.authority.contains('BLVIP')) {
                _selectVip = true;
                break;
              }else{
                _selectVip = false;
              }
            }
          }

          return Scaffold(
            appBar: AppBar(
              elevation: 0,
              leading: Container(
                child: InkWell(
                  child: Center(
                    child: Text(
                      YBChineseText.cancelTitle,
                      style: YBTextStyle.TextStyle1B1C1F15Medium,
                    ),
                  ),
                  onTap: () async {
                    YBNavigatorUtil.goDefaultBack(context);
                  },
                ),
              ),
              title: Center(
                child: Column(
                  children: [
                    Container(
                      child: Text(YBChineseText.workTaiContentDetailTitle,style: YBTextStyle.TextStyle18181816Medium,),
                    ),
                  ],
                ),
              ),
              actions: [
                Container(
                  width: YBTextStyle.adapterSize80,
                  child: Padding(
                    padding: EdgeInsets.only(left: YBTextStyle.adapterSize10,right: YBTextStyle.adapterSize10,top: YBTextStyle.adapterSize13,bottom: YBTextStyle.adapterSize13),
                    child: RawMaterialButton(
                      fillColor: YBColor.commonThemeColor,
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.all(Radius.circular(YBTextStyle.adapterSize5)),
                      ),
                      child: Text(
                        YBChineseText.workTaiShareTitle,
                        style: YBTextStyle.TextStyleFFFFFF16Medium,
                      ),
                      onPressed: () async {
                        if(_selectVip == true){
                          YBWeChatPopPage.showWeChatPopPage(context,urlStr:"${YBApi.Base_ShareImage_URL}/$id?code=${uerInfo.mineUserInfoModel.customerCode}&type=1",title:title,description:description,thumbNailStr:"common_headerdefault");
                        }else{
                          YBZuZhiGuanLiQuanXianPage.showZuZhiGuanLiQuanXian(context);
                        }
                      },
                    ),
                  ),
                ),
              ],
            ),
            body:Column(
              children: [
                Container(
                  height: YBTextStyle.adapterSize80,
                  color: YBColor.white,
                  child: Container(
                    child: Padding(
                      padding:EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.start,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Container(
                            width:YBTextStyle.adapterSize40,
                            height: YBTextStyle.adapterSize40,
                            decoration: BoxDecoration(
                              image: DecorationImage(
                                image: CachedNetworkImageProvider(uerInfo.mineUserInfoModel.avatarUrl),
                              ),
                            ),
                          ),
                          Container(
                            width: YBTextStyle.adapterSize10,
                          ),
                          Expanded(
                            child: Column(
                              mainAxisAlignment: MainAxisAlignment.center,
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Container(
                                  child: Text(uerInfo.mineUserInfoModel.nickName??YBChineseText.workTaiNameTitle,style: YBTextStyle.TextStyle18181814Medium,),
                                ),
                                Container(
                                  height: YBTextStyle.adapterSize8,
                                ),
                                Container(
                                  child: Text(
                                    uerInfo.mineUserInfoModel.customerName??"",style: YBTextStyle.TextStyle30313312,
                                  ),
                                ),
                              ],
                            ),
                          ),
                          Container(
                            child: InkWell(
                              child: Column(
                                mainAxisAlignment: MainAxisAlignment.center,
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Container(
                                    child: Image.asset(YBImageStyle.getImagePath('find_newTelePhone')),
                                  ),
                                  Container(
                                    child: Text(YBChineseText.workTaiTelPhoneTitle,style: YBTextStyle.TextStyle30313312,),
                                  ),
                                ],
                              ),
                              onTap: () async {
                                YBCallPhoneUtils().getCallPhoneUtils("tel:${uerInfo.mineUserInfoModel.customerPhone}");
                              },
                            ),
                          ),
                          Container(
                            width: YBTextStyle.adapterSize10,
                          ),
                          Container(
                            child: InkWell(
                              child: Column(
                                mainAxisAlignment: MainAxisAlignment.center,
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Container(
                                    child: Image.asset(YBImageStyle.getImagePath('find_wechatNewImage')),
                                  ),
                                  Container(
                                    child: Text(YBChineseText.workTaiJoinInWeChatTitle,style: YBTextStyle.TextStyle30313312,),
                                  ),
                                ],
                              ),
                              onTap: () async {

                              },
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                ),
                Expanded(
                  child:WebView(
                    initialUrl: '${YBApi.Base_QuanCeng_URL}/$id?from=app',
                    javascriptMode:JavascriptMode.unrestricted,
                    onPageStarted: (url){
                      EasyLoading.show(status: "读取中...");
                    },
                    onPageFinished: (url){
                      EasyLoading.dismiss();
                    },
                  ),),
              ],
            ),
          );
        }),),
    );
  }
}



